package com.the_ring.chapter13.server;


import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOServer;

public class SocketServer {

    public static void main(String[] args) {
        Configuration config = new Configuration();
        config.setPort(9010);       // 设置监听端口
        final SocketIOServer server = new SocketIOServer(config);
        // 添加连通的监听事件
        server.addConnectListener(client -> {
            System.out.println(client.getSessionId().toString() + "已连接");
        });
        // 添加连接断开的监听事件
        server.addDisconnectListener(client -> {
            System.out.println(client.getSessionId().toString() + "已断开");
        });
        // 添加文本发送的事件监听器
        server.addEventListener("send_text", String.class, ((client, data, ackSender) -> {
            System.out.println(client.getSessionId().toString() + data);
            client.sendEvent("receiver_text", "不开不开我不开，妈妈没回来谁也不开");
        }));
        server.start();     // 启动 socket 服务
    }
}
